GetShootingByIdQueryHandler   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 22
dl 0
loc 23
rs 10
c 0
b 0
f 0

1 Function

Rating   Name   Duplication   Size   Complexity  
A execute 0 16 2
1
import { QueryHandler } from '@nestjs/cqrs';
2
import { Inject } from '@nestjs/common';
3
import { GetShootingByIdQuery } from './GetSchootingByIdQuery';
4
import { IShootingRepository } from 'src/Domain/School/Repository/IShootingRepository';
5
import { ShootingView } from '../../View/ShootingView';
6
import { ShootingNotFoundException } from 'src/Domain/School/Exception/ShootingNotFoundException';
7
8
@QueryHandler(GetShootingByIdQuery)
9
export class GetShootingByIdQueryHandler {
10
  constructor(
11
    @Inject('IShootingRepository')
12
    private readonly shootingRepository: IShootingRepository
13
  ) {}
14
15
  public async execute(query: GetShootingByIdQuery): Promise<ShootingView> {
16
    const shooting = await this.shootingRepository.findOneById(query.id);
17
18
    if (!shooting) {
19
      throw new ShootingNotFoundException();
20
    }
21
22
    return new ShootingView(
23
      shooting.getId(),
24
      shooting.getName(),
25
      shooting.getStatus(),
26
      shooting.getShootingDate(),
27
      shooting.getGroupClosingDate(),
28
      shooting.getIndividualClosingDate(),
29
      shooting.getNotice()
30
    );
31
  }
32
}
33